#ifndef __SENDRCV_H__
#define __SENDRCV_H__

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h> 
#include <unistd.h>
#include "pub_log.h"
#include "md5.h"

#define MSGDATALEN (2048)
#define FILENAMELEN (256)

#define U_CHECK ('1')		//检查是否有新版本
#define U_UPDATE ('2')		//获取新版本文件列表
#define U_DOWNLOAD ('3')  	//下载文件	
#define U_EXIT ('4')		//退出		

typedef struct _msg{
	char type;
	char data[MSGDATALEN];
} msg_t;

#define WAITSECONDS (30)
#define ONCE_FILE_BLOCK (2048)

typedef struct _sfile{
	char fileLen[16];		//文件长度
	char fileName[FILENAMELEN];	//文件名
	char fileMd5[MD5_STR_LEN + 1];  //文件MD5值
	char resCode[5];		//应答码 E000代表无错误
} sfile_t;

#define SERVERFILEPATH "/home/xjy/update/"
#define CLIENTFILEPATH "/home/xjy/update1/"
#define UPDATEINFO "update.xml"

long get_file_size( char *filename );
int sevr_put_file(int sockId, char *fileName);
int cli_get_file(int sockId);
int file_put(int sockId,char *cfileName,int iFileLen);
int file_get(int sockId,char *cfileName,int iFileLen);
int Sock_recv(int iSocketID,char *buf,int length,int timeout);
int Sock_send(int iSocketID,char *buf,int length,int timeout);
int Sock_waitfor_write(int iSocketID,int waitseconds);
int Sock_waitfor_read(int iSocketID,int waitseconds);

#endif//__SENDRCV_H__
